#include <stdio.h>

void sort(int* array, unsigned int nCnt)
{
    unsigned int ivl = 1;
    int value;
    int index;

    while (ivl < nCnt)
        ivl = 3 * ivl + 1;

    while (ivl > 0)
    {
        for (unsigned int i = ivl; i < nCnt; i++)
        {
            value = array[i];
            index = i - ivl;
            while (index >= 0 && array[index] > value)
            {
                array[index + ivl] = array[index];
                index = index - ivl;
            }
            array[index + ivl] = value;
        }
        ivl = ivl / 3;
    }
}

int main()
{
    int array[8] = { 2,8,5,1,3,11,7,2 };

    sort(array, sizeof(array) / sizeof(int));

    for (unsigned int i = 0; i < (sizeof(array) / sizeof(int)); ++i)
        printf("%d ", array[i]);
    puts("");

    return 0;
}